import pygame
class Player(pygame.sprite.Sprite):
    
    def __init__(self,width,height):
        pygame.sprite.Sprite.__init__(self)
        
        self.image=pygame.transform.smoothscale(pygame.image.load('images/player1.png').convert_alpha(),(100,100))
        self.image2=pygame.transform.smoothscale(pygame.image.load('images/player2.png').convert_alpha(),(100,100))
        self.health_image=pygame.transform.smoothscale(pygame.image.load('images/player_health.png').convert_alpha(),(57,66))
        self.speed=8
        self.rect=self.image.get_rect()
        self.width,self.height=width,height
        self.rect.left,self.rect.bottom=(self.width-self.rect.width)//2,self.height-60
        self.mask=pygame.mask.from_surface(self.image)
        self.change_body=1
        self.health=3
        self.invincible_code=False
        self.alive=True
    def moveUp(self):
        if self.rect.top>0:
            self.rect.top-=self.speed
        else:
            self.rect.top=0
    def moveDown(self):
        if self.rect.bottom<self.height-60:
            self.rect.bottom+=self.speed
        else:
            self.rect.bottom=self.height-60
    def moveLeft(self):
        if self.rect.left>0:
            self.rect.left-=self.speed
        else:
            self.rect.left=0
    def moveRight(self):
        if self.rect.right<self.width:
            self.rect.right+=self.speed
        else:
            self.rect.right=self.width
    def reset(self):
        self.rect.left,self.rect.bottom=(self.width-self.rect.width)//2,self.height-60
        self.health-=1
        self.alive=True

    def changeBody(self,pos):
        self.change_body=-self.change_body
        if self.change_body==1:
            self.image=pygame.transform.smoothscale(pygame.image.load('images/player1.png').convert_alpha(),(100,100))
            self.image2=pygame.transform.smoothscale(pygame.image.load('images/player2.png').convert_alpha(),(100,100))
            self.rect=self.image.get_rect()
            self.rect.left,self.rect.bottom=pos[0]-35,pos[1]-35
            self.mask=pygame.mask.from_surface(self.image)
        if self.change_body==-1:
            self.image=pygame.transform.smoothscale(pygame.image.load('images/player1.png').convert_alpha(),(30,30))
            self.image2=pygame.transform.smoothscale(pygame.image.load('images/player2.png').convert_alpha(),(30,30))
            self.rect=self.image.get_rect()
            self.rect.left,self.rect.bottom=pos[0]+35,pos[1]+35
            self.mask=pygame.mask.from_surface(self.image)
